﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RoleHelper
{
    public partial class login : UserControl
    {
        private string name;
        private string pass;
        private string server;
        private string port;
        private string dbase;

        public event EventHandler OnConnect;

        public login()
        {
            InitializeComponent();
        }

        public void setdbase(string db)
        {
            dbase = db;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            name = Preuser.Text;
            pass = Prepassword.Text;
            dbase = "rolecosas";
            Program.bdatos.crearPred(dbase, name, pass);
            if (Program.bdatos.conectar() == false)
            {
                MessageBox.Show("No se pudo establecer conexión con la base de datos", "Error",MessageBoxButtons.OK);
            }
            else
            {
                OnConnect(null, null);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            name = Avuser.Text;
            pass = Avpassword.Text;
            server = Avserver.Text;
            port = Avport.Text;
            dbase =Avdb.Text;
            Program.bdatos.crarAv(server, dbase, name, pass, port);
            if (Program.bdatos.conectar() == false)
            {
                MessageBox.Show("No se pudo establecer conexión con la base de datos", "Error",MessageBoxButtons.OK);
            }
            else
            {
                OnConnect(null, null);
            }
        }
    }
}
